'use strict'

function getProduct(keyword) {
    return new Promise(function (res, rej) {
        $.get('http://localhost:3000/product?keyword=' + keyword, data => {
            res(data)
        })
    })
}

function getProductId(id){
    return new Promise(function (res, rej) {
        $.get(`http://localhost:3000/product/${id}`, data => {
            res(data)
        })
    })
}

function postProduct(obj){
    return new Promise(function (res, rej) {
        $.post('http://localhost:3000/product',obj, data => {
            res(data)
        })
    })
}

function putProduct(id,obj){
    return new Promise(function (res, rej) {
        $.ajax({
            url:`http://localhost:3000/product/${id}`,
            type:'put',
            data:obj,
            success:data=>{
                res(data)
            }
        })
    })
}
function delProductId(id){
    return new Promise(function (res, rej) {
        $.ajax({
            url:`http://localhost:3000/product/${id}`,
            type:'delete',
            success:data=>{
                res(data)
            }
        })
    })
}